package com.yuanfeng.base.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanfeng.base.dto.DealerLevelInfoDTO;
import com.yuanfeng.base.entity.BaseDealerLevelInfoEntity;
import com.yuanfeng.base.mapper.BaseDealerLevelInfoMapper;
import com.yuanfeng.base.service.BaseDealerLevelInfoService;
import com.yuanfeng.base.vo.DealerLevelInfoVO;
import com.yuanfeng.commoms.util.ResponseResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName BaseDealerLevelInfoServiceImpl
 * @Description  经销商等级
 * @Author cyp
 * @Date 2023-08-04 18:18:38
 * @Version 1.0
 **/
@Service
public class BaseDealerLevelInfoServiceImpl extends ServiceImpl<BaseDealerLevelInfoMapper, BaseDealerLevelInfoEntity>
        implements BaseDealerLevelInfoService {

    @Override
    public ResponseResult operateDealerLevel(DealerLevelInfoDTO dealerLevelInfo) {
        switch (dealerLevelInfo.getOperateType()){
            case 1:
                // 新增
                this.baseMapper.insertSelective(dealerLevelInfo);
                break;
            case 2:
                // 编辑
                this.baseMapper.updateByPrimaryKeySelective(dealerLevelInfo);
                break;
            case 3:
                // 1 正常  2 删除
                dealerLevelInfo.setDealerLevelStatus(2);
                this.baseMapper.updateByPrimaryKeySelective(dealerLevelInfo);
                break;
            case 4:
                // 查询指定等级
                dealerLevelInfo = this.baseMapper.selectByPrimaryKey(dealerLevelInfo.getDealerLevelId());
                break;
            default:
                break;
        }
        return ResponseResult.success(dealerLevelInfo);
    }

    @Override
    public ResponseResult queryDealerLevel(DealerLevelInfoDTO dealerLevelInfo) {
        List<DealerLevelInfoVO> dealerLevelInfos = this.baseMapper.queryDealerLevelInfo(dealerLevelInfo);
        return ResponseResult.success(dealerLevelInfos);
    }
}
